package com.corex.vinayak.views;

import com.corex.utils.Constants;
import com.corex.vinayak.R;
import com.corex.vinayak.TimeTableDetailsActivity;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CalendarView;
import android.widget.CalendarView.OnDateChangeListener;
import android.widget.Toast;

public class LoginSuccessFragment extends Fragment{
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		final View rootView = inflater.inflate(R.layout.first_welcome_layout, container, false);
		CalendarView calendarView = (CalendarView) getActivity().findViewById(R.id.drawer_calendar);


        calendarView.setOnDateChangeListener(new OnDateChangeListener() {
			@Override 
			public void onSelectedDayChange(CalendarView view, int year, int month,
					int dayOfMonth) {
				Bundle bundle = new Bundle();
				final TimeTableDetailsActivity timeTableDetailsFragment = new TimeTableDetailsActivity();
				final FragmentManager fragmentManager = getFragmentManager();
				month++;
				Toast.makeText(rootView.getContext(),"Fetching...", Toast.LENGTH_SHORT).show();
				String date = year+"-"+month+"-"+dayOfMonth;
				bundle.putString(Constants.TIMETABLE_SELECTED_DATE, date);
				// set Fragmentclass Arguments
				Bundle bundleOther = timeTableDetailsFragment.getArguments();
				if(bundleOther==null){
					timeTableDetailsFragment.setArguments(bundle);
				}else{
					timeTableDetailsFragment.getArguments().putString(Constants.TIMETABLE_SELECTED_DATE, date);
				}
				
				FragmentTransaction transaction = fragmentManager.beginTransaction();
				transaction.replace(R.id.loginsuccesscontainer, timeTableDetailsFragment);
				transaction.addToBackStack(null);
				transaction.commit();
			}
		});
		return rootView;
	}


}
